package ru.alt22.visor.php.core.codegen;

import java.util.ArrayList;

public class PHPMethodCollection {
	
	private ArrayList<PHPMethod> methods; 

	public PHPMethodCollection() {
		methods = new ArrayList<PHPMethod>();
	}

	public int length() {
		return methods.size();
	}

	public PHPMethod get(int index) {
		return methods.get(index);
	}

	public void add(PHPMethod method) {
		if (contains(method)) {
			return;
		}
		methods.add(method);
	}

	public void addAll(ArrayList<PHPMethod> methods) {
		for (int i = 0; i < methods.size(); i++) {
			add(methods.get(i));
		}
	}

	public void remove(String method) {
		for (int i = 0; i < methods.size(); i++) {
			if (methods.get(i).getName().compareToIgnoreCase(method) == 0) {
				methods.remove(methods.get(i));
			}
		}
	}

	public void remove(PHPMethod method) {
		remove(method.getName());
	}

	public ArrayList<PHPMethod> toArrayList() {
		return methods;
	}

	public boolean contains(String method) {
		for (int i = 0; i < methods.size(); i++) {
			if (methods.get(i).getName().compareToIgnoreCase(method) == 0) {
				return true;
			}
		}
		return false;
	}

	public boolean contains(PHPMethod method) {
		return contains(method.getName());
	}

}
